package com.xlh.dto.course;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xlh.enums.LocalResourcesEnum;
import com.xlh.enums.course.TemplateTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * 模板结果集
 * <p>
 * Created by lx on 2019/3/14.
 */
@Data
public class TemplateDetailDTO {

    @ApiModelProperty(value = "模板id")
    @JsonIgnore
    private Long id;

    @ApiModelProperty(value = "教师id")
    @JsonIgnore
    private Long userId;

    @ApiModelProperty(value = "类型：TemplateTypeEnum")
    @JsonIgnore
    private Integer type;

    @ApiModelProperty(value = "资源的id")
    @JsonIgnore
    private Long resourceId;

    @ApiModelProperty(value = "系统中资源名")
    private String name;

    @ApiModelProperty(value = "文件名")
    private String fileName;

    @ApiModelProperty(value = "备注（可填写资源目录）")
    @JsonIgnore
    private String remark;

    @ApiModelProperty(value = "资源类型：ResourcesTypeEnum")
    @JsonIgnore
    private Integer resourceType;

    @ApiModelProperty(value = "文件路径")
    @JsonIgnore
    private String filePath;

    @ApiModelProperty(value = "编辑器内容")
    private String editContent;

    public String getFilePath() {
        if (StringUtils.isBlank(fileName)) return null;
        TemplateTypeEnum codeEnum = TemplateTypeEnum.getByCode(type);
        if (codeEnum == TemplateTypeEnum.COURSE_REPORT) {
            return LocalResourcesEnum.COURSE_TEMPLATE.getMappingUrl(fileName);
        }
        if (codeEnum == TemplateTypeEnum.TEST_REPORT) {
            return LocalResourcesEnum.TEST_TEMPLATE.getMappingUrl(fileName);
        }
        return null;
    }
}
